package cn.tarena.ht.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.tarena.ht.mapper.RoleMapper;
import cn.tarena.ht.pojo.Role;

@Service
public class RoleServiceImpl implements RoleService {
	@Autowired
	private RoleMapper roleMapper;

	public List<Role> findAll() {
		return roleMapper.findAll();
	}

	public void saveRole(Role role) {
		roleMapper.saveRole(role);
	}

	public void deleteRole(String[] roleIds) {
		for (String roleId : roleIds) {
			roleMapper.deleteRoleModule(roleId);
			roleMapper.deleteUserRole(roleId);
			roleMapper.deleteRole(roleId);
		}
	}

	public Role findRole(String roleId) {
		return roleMapper.findRole(roleId);
	}

	public void updateRole(Role role) {
		roleMapper.updateRole(role);
	}

	public void saveRoleModule(String roleId, String[] moduleIds) {
		roleMapper.deleteRoleModule(roleId);
		for (String moduleId : moduleIds) {
			roleMapper.saveRoleModule(roleId,moduleId);
		}
	}

	public List<String> findModules(String roleId) {
		return roleMapper.findModules(roleId);
	}

	public void deleteRoleModule(String roleId) {
		roleMapper.deleteRoleModule(roleId);
	}
}
